/**
*      author: Y_Yao
*      created: 2025-03-21 20:09:09
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 300 + 7;
int dp[N][N];
int m[N];
int n;
int sum[N];

void solve()
{
    cin >> n;    
    memset(dp,INF,sizeof dp);
    for(int i = 1;i <= n;i++)
    {
        cin >> m[i];
        sum[i] = sum[i-1] + m[i];
        dp[i][i] = 0;
    }

    for(int len = 1;len < n;len++)
    {
        for(int i = 1;i <= n - len;i++)
        {
            int j = i + len;
            for(int k = i;k < j;k++)
            {
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k+1][j] + sum[j] - sum[i-1]);
            }
        }
    }
    cout << dp[1][n] << endl;

}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}